package com.dhy.controller;

import com.dhy.dto.PermissionDto;
import com.dhy.pojo.BasePojo;
import com.dhy.pojo.Permission;
import com.dhy.pojo.relation_pojo.EmployeeAndRole;
import com.dhy.service.IBaseService;
import com.dhy.service.IPermissionService;
import com.dhy.service.imp.PermissionServiceImpl;
import com.dhy.utils.AjaxResult;
import com.dhy.utils.annotation.MyPermissionAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("permissions")
@CrossOrigin
@MyPermissionAnnotation(name = "权限管理")
public class PermissionController extends BaseController<Permission> {

    @Autowired
    IPermissionService iPermissionService;

    @GetMapping("treeData")
    public AjaxResult selectPermissionTree() {
        AjaxResult ajaxResult = AjaxResult.ajaxResultBuild();
        try {
            List<PermissionDto> permissionDtoList = iPermissionService.selectPermissionTree();
            ajaxResult.setMessage("操作成功").setSuccess(true).setData(permissionDtoList);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult.setMessage("操作失败").setSuccess(false);
        }
        return ajaxResult;
    }
}

